fix: prevent empty strings from overwriting step content in data layer#2790
Open
Pranjalya wants to merge 2 commits intoChainlit:mainfrom
Open
fix: prevent empty strings from overwriting step content in data layer#2790Pranjalya wants to merge 2 commits intoChainlit:mainfrom
Pranjalya wants to merge 2 commits intoChainlit:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #2789
Description
In the
ChainlitDataLayer, thecreate_stepmethod uses anINSERT ... ON CONFLICT DO UPDATEpattern withCOALESCE. BecauseStepobjects initializeinputandoutputas""(empty string) instead ofNone, the database treats the empty string as a valid value to update, rather than a "missing" value to ignore.This PR ensures that
inputandoutputare passed asNone(SQLNULL) if they are empty strings. This allows the existingCOALESCElogic in the SQL query to correctly preserve existing content if a late-arriving "initial" save task executes after a "final" update task.Changes
Modified
backend/chainlit/data/chainlit_data_layer.py:paramsdictionary increate_stepto convert emptyinputandoutputstrings toNone.Testing
Verified using the reproduction script provided in the associated issue. With this change, the
COALESCEfunction correctly identifies theNULLvalue and maintains the existing content even if the tasks finish out of order.Summary by cubic
Prevents empty input/output strings from overwriting existing step content by treating them as NULL in the data layer, preserving final step data when saves finish out of order.
Written for commit 1d92838. Summary will update on new commits.